/******************************************************************************
 * SVN­Version­Information:
 * ­­­­­­­­­­­­­­­­­­­­­­­­---------------------
 * $LastChangedRevision: 6 $
 * $LastChangedBy: c.a.duevel $
 * $LastChangedDate: 2009-08-26 15:12:37 +0000 (Wed, 26 Aug 2009) $
 * $HeadURL: http://robofight.googlecode.com/svn/trunk/Server/src/de/hft_stuttgart/botwar/server/model/StandardMode.java $
 ******************************************************************************/
package de.hft_stuttgart.botwar.server.model;

import de.hft_stuttgart.botwar.common.models.Position;
import java.util.Collection;

/**
 *
 * @author c.a.duevel@gmail.com
 */
class StandardMode extends RobotMode {

    private Robot lastFiredAt;

    Robot fireAt(final Robot thisRobot,
            final Collection<Robot> robots) {
        if (lastFiredAt != null &&
                !lastFiredAt.isDead() &&
                thisRobot.isInRange(lastFiredAt)) {
            return lastFiredAt;
        } else {
            Robot robotToFireAt = null;
            for (Robot r : robots) {
                if (thisRobot.isEnemy(r) && thisRobot.isInRange(r)) {
                    if (robotToFireAt == null) {
                        robotToFireAt = r;
                    } else {
                        robotToFireAt =
                                robotToFireAt.distanceTo(thisRobot) >
                                r.distanceTo(thisRobot)
                                ? r : robotToFireAt;

                    }
                }

            }
            lastFiredAt = robotToFireAt;
            return robotToFireAt;

        }
    }

    Position getTarget(final Robot thisRobot, final Collection<Robot> robots) {
        return thisRobot.getUserTarget();
    }
}
